import multiprocessing

if __name__ == '__main__':
    q = multiprocessing.Queue(3)

    print('queue size:', q.qsize())
    print('queue is empty:', q.empty())
    print('queue is full:', q.full())

    q.put(1)
    q.put(2)
    q.put(3)
    # q.put(4)  # 队列已满，阻塞

    print(q.get())
    print(q.get())
    print(q.get())
    # print(q.get())  # 队列已空，阻塞

    q.put_nowait(4)
    print(q.get_nowait())  # 队列已空，不阻塞
    print(q.get(True, 2))  # 队列已空，等待2秒

    print(q.qsize())  # 队列大小
    print(q.empty())  # 队列是否为空
    print(q.full())  # 队列是否已满

    q.close()  # 关闭队列
    q.join_thread()  # 等待队列中的所有进程结束
    print('main process end')
